var xmlHttp;

function createXMLHttpRequest()
{
	if ( window.ActiveXObject )
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if ( window.XMLHttpRequest )
	{
		xmlHttp = new XMLHttpRequest();
	}
}

function validate()
{
	createXMLHttpRequest();
	var date = document.getElementById("birthDate");
	var url = "post-new-server.php?category_id=";
	xmlHttp.open( "GET", url, true );
	xmlHttp.onreadystatechange = callback;
	xmlHttp.send( null );
}

function get_category_customfields( category_id )
{

	createXMLHttpRequest();

	var url = "post-new-server.php?category_id=" + category_id;
	xmlHttp.open( "GET", url, true );

	xmlHttp.onreadystatechange = callback;

	xmlHttp.send( null );
}

function callback()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{

			setMessage();
		}
	}
}

function setMessage()
{
	var customfields = xmlHttp.responseXML.getElementsByTagName("customfield");
	var customvalues = xmlHttp.responseXML.getElementsByTagName("customkey");
	var customtypes = xmlHttp.responseXML.getElementsByTagName("customtype");
	var customarguments = xmlHttp.responseXML.getElementsByTagName("customargument");
	var htmlmessage = "\n<table>\n";
	var i = 0;

	for( i = 0; i < customfields.length; i++ )
	{
		htmlmessage += "<tr>\n";
		htmlmessage += "<th>" + customfields[i].firstChild.data + "</th>\n<td>";
		switch( customtypes[i].firstChild.data )
		{
			case 'input':
			if( customarguments[i].firstChild.data != 0 )
				htmlmessage += "<input type=\"text\" name=\"" + customvalues[i].firstChild.data + "\" value=\"\" size=\"" + customarguments[i].firstChild.data + "\"/>";
			else
				htmlmessage += "<input type=\"text\" name=\"" + customvalues[i].firstChild.data + "\" value=\"\" />";
			break;
		
		}
		htmlmessage += "</td>\n</tr>\n";
	}
	htmlmessage += "</table>\n";
	
	document.getElementById( "custom_field" ).innerHTML = htmlmessage;
}








